package com.onlyphoto.onlymall.mvp.presenter

import android.content.Context
import com.onlyphoto.onlymall.base.BaseEntity
import com.onlyphoto.onlymall.base.BaseNetworkResponse
import com.onlyphoto.onlymall.base.BaseObserver

import com.onlyphoto.onlymall.mvp.contract.CUpdatePwd
import com.onlyphoto.onlymall.mvp.model.MUpdatePwdImpl
import com.onlyphoto.onlymall.base.BasePresenter


class PUpdatePwdImpl(mContext: Context, mView: CUpdatePwd.IVUpdatePwd) : BasePresenter<CUpdatePwd.IVUpdatePwd, MUpdatePwdImpl>(mContext, mView, MUpdatePwdImpl()), CUpdatePwd.IPUpdatePwd {
    override fun updatePwd() {
        val bean = mView.getUpdatePwdBean()
        mModel.updatePwd(bean, object :BaseObserver<BaseEntity>(mContext.get()){
            override fun onSuccess(data: BaseEntity?, msg: String?) {
                mView.updatePwdSuccess()
            }

            override fun onCodeError(t: BaseNetworkResponse<BaseEntity>?) {
                if (t?.error_code == 1 || t?.error_code == 2) {
                    mView.showMsg(t.msg!!)
                } else {
                    mView.showMsg("网络错误，请稍后重试")
                }
            }

            override fun onFailure(e: Throwable?) {
                mView.showMsg("网络错误，请稍后重试")
            }

            override fun onRequestStart() {
            }

            override fun onFinally() {
            }

        })
    }
}
